//
// Created by darcy on 4/27/21.
//

#include "../Include/Order.h"
#include <iostream>

using namespace std;

void Order::getID(vector<Account> &account) {
    int temp;
    bool t = false;
    cout << "Enter an id:";
    cin >> temp;
    for (auto &i : account) {
        if (temp == i.id) {
            t = true;
            showMenu();
            getOrder(i);
        } else
            continue;
    }
    if (!t)
        cout << "Please enter the correct ID!" << endl;
    Order::getID(account);
}

void Order::getOrder(Account &account) {
    int order;
    bool t = true;
    cout << "Enter a choice:";
    cin >> order;
    switch (order) {
    case 1:
        Order::showBalance(account);
        break;
    case 2:
        Order::withdraw(account);
        break;
    case 3:
        Order::deposit(account);
        break;
    case 4:
        t = false;
        break;
    default:
        t = true;
    }
    if (t)
        Order::getOrder(account);
}

void Order::showBalance(Account &account) {
    cout << "The balance is:" << account.getBalance() << endl;
}

void Order::withdraw(Account &account) {
    float temp;
    bool t = false;
    cout << "Enter an amount to withdraw:";
    cin >> temp;
    t = account.withdraw(temp);
    if (!t)
        cout << "No enough money!" << endl;
}

void Order::deposit(Account &account) {
    float temp;
    cout << "Enter an amount to deposit:";
    cin >> temp;
    account.deposit(temp);
}

void Order::showMenu() {
    cout << "Main menu" << endl;
    cout << "1:check balance" << endl;
    cout << "2:withdraw" << endl;
    cout << "3:deposit" << endl;
    cout << "4:exit" << endl;
}
